@rbxts/jsnatives



Proxy - len hook

The len hook is triggered when the length or size of the proxy is requested.

Signature

function len<T>(target: T, proxy: T): number;

Description

The len handler trap is called when the size of the proxy object is being determined, such as when using the length property on an array or the size property on a Map or Set.

Parameters

Return value

Examples

Basic length customization for arrays

const array = [1, 2, 3, 4, 5];
const proxy = new Proxy(array, {
len: (target, proxy) => {
console.log("Length requested");
// Return a custom length
return target.length * 2;
}
});
console.log(proxy.length); // Logs: "Length requested", then 10